package com.imcoke.abchat.common;

import com.imcoke.abchat.domain.User;

/**
 * @Author ccoke
 * @Description SQL生成类
 * @Date: 11:18 2017-11-29
 */

public class SQLProvider {
    public String updateUser(User user){
        Boolean flag = false;
        StringBuilder sql = new StringBuilder();
        sql.append( "UPDATE tb_user SET");
        if (user.getPassword() != null){
            sql.append( " password = #{password}");
            flag = true;
        }
        if (user.getEmail() != null){
            if (flag)
                sql.append(",");
            sql.append( " email = #{email}");
            flag = true;
        }
        if (user.getHeadimage() != null){
            if (flag)
                sql.append(",");
            sql.append(" headimage = #{headimage}");
            flag = true;
        }
        if (user.getNickname() != null){
            if (flag)
                sql.append(",");
            sql.append(" nickname = #{nickname}");
            flag = true;
        }
        if (user.getLasttime() != null){
            if (flag)
                sql.append(",");
            sql.append(" lasttime = #{lasttime}");
            flag = true;
        }
        if (user.getModifytime() != null){
            if (flag)
                sql.append(",");
            sql.append(" modifytime = #{modifytime}");
        }
        sql.append(" WHERE id = #{id};");
        return sql.toString();
    }
}
